using System;

namespace GeneticAlgorithms.Factories
{
    /// <summary>
    /// Factory class for cloneable genomes.
    /// </summary>
    /// <typeparam name="TGenome">The type of the genome.</typeparam>
    public class CloneableGenomeFactory<TGenome> : IGenomeFactory<TGenome>
        where TGenome : ICloneable
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="CloneableGenomeFactory&lt;TGenome&gt;"/> class.
        /// </summary>
        /// <param name="cloneableGenome">The cloneable genome.</param>
        public CloneableGenomeFactory(TGenome cloneableGenome)
        {
            cloningSource = (ICloneable)cloneableGenome;
        }

        private ICloneable cloningSource;

        #region IGenomeFactory<TGenome,TGene> Members

        /// <summary>
        /// Creates a genome.
        /// </summary>
        /// <returns>A new genome object.</returns>
        public TGenome CreateGenome()
        {
            return (TGenome)cloningSource.Clone();
        }

        #endregion

    }
}
